<template>
  <view>
    <view class="home_tab">
      <view class="home_tab_title">
        <view class="title_inner"> <uni-segmented-control :current="current" :values="tabName.map((v) => v.title)" @clickItem="onClickItem" styleType="text" activeColor="#d4237a"></uni-segmented-control> </view>
        <navigator url="/pages/search/index" class="iconfont iconsearch"></navigator>
      </view>
      <view class="content">
        <view v-if="current === 0">
          <home-recommend></home-recommend>
        </view>
        <view v-if="current === 1">
          <home-category></home-category>
        </view>
        <view v-if="current === 2">
          <home-album></home-album>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import homeAlbum from "./home-album";
import homeCategory from "./home-category";
import homeRecommend from "./home-recommend";
import { uniSegmentedControl } from "@dcloudio/uni-ui";
export default {
  data() {
    return {
      tabName: [{ title: "推荐" }, { title: "分类" }, { title: "专辑" }],
      current: 0,
      componentIndex: "home-album",
    };
  },
  methods: {
    onClickItem(e) {
      if (this.current !== e.currentIndex) {
        this.current = e.currentIndex;
      }
    },
  },
  components: {
    homeAlbum,
    homeCategory,
    homeRecommend,
    uniSegmentedControl,
  },
};
</script>

<style lang="scss">
.home_tab_title {
  position: relative;
  .title_inner {
    width: 60%;
    margin: 0 auto;
  }
  .iconsearch {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 5%;
  }
}
</style>
